package com.zr.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zr.model.UserMsg;
import com.zr.service.SelectAllUserMsgService;
import com.zr.service.impl.SelectAllUserMsgServiceImpl;

import net.sf.json.JSONObject;

/**
 * 处理查询全部用户信息请求
 * @author lzq
 *
 */
public class SelectAllUserMsgAction extends HttpServlet{
	private SelectAllUserMsgService selectAllUserMsgService = new SelectAllUserMsgServiceImpl();
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setCharacterEncoding("utf-8");
		PrintWriter pw = resp.getWriter();
		JSONObject json = new JSONObject();
		int  page =  Integer.parseInt(req.getParameter("page"));
		int  pageSize = Integer.parseInt(req.getParameter("rows"));
		List<UserMsg> userMsgs = selectAllUserMsgService.getAllUserMsgByPageByPagesize(page, pageSize);
		int userNumber = selectAllUserMsgService.getAllUserNumber();
		json.put("total", userNumber);
		json.put("rows",userMsgs);
		pw.write(json.toString());
	}
}
